<?php
/**
 * Error controller
 *
 * @category    IPB_CMS
 * @package     Application_Module_Default
 * @subpackage  Controller
 * @copyright   Copyright (c) 2009 IPB CMS <http://ipb-cms.googlecode.com/>
 * @license     http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
 * @author      Henrique Moody <henriquemoody@gmail.com>
 */
class ErrorController extends Zend_Controller_Action
{
    /**
     * Error action
     *
     * @return void
     */
    public function errorAction()
    {
        $this->view->layout()->disableLayout();
        $errors = $this->_getParam('error_handler');
        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                $this->getResponse()->setHttpResponseCode(404);
                $this->view->title   = 'Object not found!';
                $this->view->message = 'The link on the referring page seems '
                                     . 'to be wrong or outdated. If you entered '
                                     . 'the URL manually please check your '
                                     . 'spelling and try again.';
                break;
            default:
                $this->getResponse()->setHttpResponseCode(500);
                $this->view->title  = 'Server error!';
                //$this->view->title  = 'Erro interno do servidor';
                $this->view->message = 'The server encountered an internal error '
                                     . 'and was unable to complete your request. '
                                     . 'Either the server is overloaded or there '
                                     . 'was an error in a CGI script.';
                $logger = Zend_Registry::get('Zend_Log');
                $logger->log($errors->exception, Zend_Log::CRIT);
                break;
        }
        $this->view->headTitle(
            $this->view->translate($this->view->title),
            'PREPEND'
        );
        $this->view->exception = $errors->exception;
        $this->view->request   = $errors->request;
        $this->view->identity  = Zend_Auth::getInstance()->getIdentity();
    }
}
